package sdk.webview.fmc.com.fmcsdk.presenter;


import sdk.webview.fmc.com.fmcsdk.base.BaseData;
import sdk.webview.fmc.com.fmcsdk.base.BasePresenter;
import sdk.webview.fmc.com.fmcsdk.base.UserApi;
import sdk.webview.fmc.com.fmcsdk.bean.DDTypeBean;
import sdk.webview.fmc.com.fmcsdk.interfaces.SettingView;
import sdk.webview.fmc.com.fmcsdk.util.Url;
import sdk.webview.fmc.com.fmcsdk.util.UserHelper;
import sdk.webview.fmc.com.fmcsdk.util.retrofit2.observer.ResponseTransformer;
import sdk.webview.fmc.com.fmcsdk.util.retrofit2.subscriber.ResponseSubscriber;

/**
 * Created by ydm on 2017/9/14.
 */

public class SettingPresenter extends BasePresenter<SettingView> {
    public void setLangList(final int which, final String code) {
        //设置多语言的数据字典

        getApi(UserApi.class).setLangList(getDefaultAddress()+ Url.CHANGE_USER_LANG, Url.XMLHTTPREQUEST, UserHelper.getToken(), UserHelper.getUserId(),code)
                .compose(new ResponseTransformer<>(this.<BaseData>bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<BaseData>() {
                    @Override
                    public void success(BaseData baseData) {

                        view.setLangListSuccess(which,code);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        view.setLangListError();
                    }

                    @Override
                    public void onRequestAgain() {
                        setLangList(which,code);
                    }


                });
    }

    public void getLang() {
        //获取多语言的数据字典

        getApi(UserApi.class).getLangList(getDefaultAddress()+ Url.GET_DD_LIST, Url.XMLHTTPREQUEST, UserHelper.getToken(), "PA_DEFAULT_LANG")
                .compose(new ResponseTransformer<>(this.<DDTypeBean>bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<DDTypeBean>() {
                    @Override
                    public void success(DDTypeBean baseData) {

                    view.getLangSuccess(baseData);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        view.setLangListError();
                    }

                    @Override
                    public void onRequestAgain() {
                    }


                });
    }
}
